Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'openapi-request-validator' componentSchemas should be an object #914

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jckr
Copy link

@jckr jckr commented Nov 14, 2024

the problem

currently, the interface of the OpenAPIRequestValidator has componentSchemas as an array of IJsonSchema.

export interface OpenAPIRequestValidatorArgs {
  customFormats?: {
    [formatName: string]: Format | FormatDefinition<string | number>;
  };
  customKeywords?: {
    [keywordName: string]: KeywordDefinition;
  };
  externalSchemas?: {
    [index: string]: IJsonSchema;
  };
  loggingKey?: string;
  logger?: Logger;
  parameters?: OpenAPI.Parameters;
  requestBody?: OpenAPIV3.RequestBodyObject;
  schemas?: IJsonSchema[];
  componentSchemas?: IJsonSchema[];
  errorTransformer?(
    openAPIResponseValidatorValidationError: OpenAPIRequestValidatorError,
    ajvError: ErrorObject
  ): any;
  ajvOptions?: Options;
  enableHeadersLowercase?: boolean;
  additionalQueryProperties?: boolean;
}

but this is incorrect, in the code we rely on the fact that componentsSchema is an object:

 Object.keys(args.componentSchemas).forEach((id) => {

with the current implementation, we will have typecheck errors whenever we try to use openapi-request-validator in TS with componentSchemas.

the solution

just a one line change to update that interface.
tests still pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant